package java学习.第08章_面向对象编程_高级;
/**
 * 类的对象只有有限个，确定的。举例如下:
 * ➢星期: Monday(星期- -)、.... Sunday(星期天)
 * ➢性别: Man(男)、Woman(女)
 * ➢季节: Spring(春 .....Winter(冬天)
 * ➢支付方式: Cash (现金)、WeChatPay (微信)、Alipay(支付宝)、
 * BankCard(银行) CreditCard(信用卡)
 * ➢就职状态: Busy、 Free、 Vocation、 Dimission
 * ➢订单状态: Nonpayment (未付款)、Paid (已付款)、Fulfilled (已配货)、
 * Delivered (已发货)、Return (退货)、Checked (已确认)
 * ➢线程状态:创建、就绪、运行、阻塞、死亡
 * <p>
 * ●当需要定义一组常量时，强烈建议使用枚举类
 */
public class H_枚举类 {
    public static void main(String[] args) {
        /**
         * enum 默认继承于java.lang.Enum
         */
        System.out.println("--------------获取参数，需要写get方法---------------------");
        System.out.println(Season.SPRING.getName());
        System.out.println(Season.SPRING.getDesc());
        System.out.println("-------------默认-------------------------");
        System.out.println(Season.SPRING);//SPRING
        System.out.println("------------name()------------------------");
        System.out.println(Season.SPRING.name());//SPRING
        System.out.println("------------values()----------------------");
        Season[] values0 = Season.values();//这两个一样
        Season[] values1 = Season.SPRING.values();//这两个一样
        for (int i = 0; i < values0.length; i++) {
            System.out.println(values0[i]);
        }
        System.out.println("------------valueOf()---------------------");
        System.out.println(Season.valueOf("SPRING"));
//        System.out.println(Season.valueOf("1232"));//找不到直接报错
        System.out.println("------------ordinal()---------------------");
        System.out.println(Season.SUMMER.ordinal());//返回次枚举是第几个 0开始
        System.out.println("------------compareTo()---------------------");
        //获取当前是枚举第几个减去 括号内 是枚举第几个
        System.out.println(Season.SUMMER.compareTo(Season.WINTER));
        System.out.println("------------枚举类方法()---------------------");
        Season.SUMMER.shows();
        Season.AUTUMN.show();

    }
}

//JDK5.0 之前
class Season5 {
    //1.声明对象属性
    private final String name;
    private final String desc;

    private Season5(String name, String desc) {
        this.name = name;
        this.desc = desc;
    }//2.私有化构造器

    public String getName() {
        return name;
    }

    public String getDesc() {
        return desc;
    }

    //3.供当前枚举类的多个对象: public static final的
    public static final Season5 SPRING = new Season5("春天", "春暖花开");
    public static final Season5 SUMMER = new Season5("夏天", "夏日炎炎");
    public static final Season5 AUTUMN = new Season5("秋天", "秋高气爽");
    public static final Season5 WINTER = new Season5("冬天", "冰天雪地");

    @Override
    public String toString() {
        return "Season5{" +
                "name='" + name + '\'' +
                ", desc='" + desc + '\'' +
                '}';
    }
}

//现在
interface info {
    void show();

    void shows();
}

//使用 enum 关键字枚举  定义的枚举类 默认继承于 java.lang.Enum 类 不要再继承父类
enum Season implements info {
    //必须在枚举类的开头声明，且用，隔开
    SPRING("春天", "春暖花开") {
        @Override
        public void show() {
            System.out.println("春天来了");
        }
    },
    SUMMER("夏天", "夏日炎炎") {
        @Override
        public void show() {
            System.out.println("夏天来了");
        }
    },
    AUTUMN("秋天", "秋高气爽") {
        @Override
        public void show() {
            System.out.println("秋天来了");
        }
    },
    WINTER("冬天", "冰天雪地") {
        @Override
        public void show() {
            System.out.println("冬天来了");
        }
    };

    @Override
    public void shows() {
        System.out.println(this.name + "来了");
    }//接口的show方法

    private final String name;
    private final String desc;

    private Season(String name, String desc) {
        this.name = name;
        this.desc = desc;
    }//2.私有化构造器  只能私有的

    public String getName() {
        return name;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public String toString() {
        return name() + ":(" + name + "," + desc + ")";
    }//重写此默认父类的 toString 方法
} //默认有toString